home *** CD-ROM | disk | FTP | other *** search
/ Explorer - Mosaic & Web / Explorer - Mosaic & Web.iso / helpers / ghostvew / src / gvwdlg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-01  |  18.8 KB  |  648 lines

  1. /* Copyright (C) 1993, 1994, Russell Lang.  All rights reserved.
  2.   
  3.   This file is part of GSview.
  4.   
  5.   This program is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the GSview Free Public Licence 
  9.   (the "Licence") for full details.
  10.   
  11.   Every copy of GSview must include a copy of the Licence, normally in a 
  12.   plain ASCII text file named LICENCE.  The Licence grants you the right 
  13.   to copy, modify and redistribute GSview, but only under certain conditions 
  14.   described in the Licence.  Among other things, the Licence requires that 
  15.   the copyright notice and this notice be preserved on all copies.
  16. */
  17.  
  18. /* gvwdlg.c */
  19. /* Dialog boxes for Windows GSview */
  20. #include "gvwin.h"
  21.  
  22. BOOL
  23. get_filename(char *filename, BOOL save, int filter, int title, int help)
  24. {
  25. LPSTR old_lpstrFile;
  26. LPCSTR old_lpstrTitle;
  27. char szTitle[MAXSTR];
  28. BOOL flag;
  29.     if (help)
  30.         LoadString(phInstance, help, szHelpTopic, sizeof(szHelpTopic));
  31.     old_lpstrTitle = ofn.lpstrTitle;
  32.     if (title) {
  33.         LoadString(phInstance, title, szTitle, sizeof(szTitle));
  34.         ofn.lpstrTitle = (LPCSTR)szTitle;
  35.     }
  36.     old_lpstrFile = ofn.lpstrFile;
  37.     if (filename != (LPSTR)NULL)
  38.         ofn.lpstrFile = filename;
  39.     ofn.nFilterIndex = filter;
  40.     if (save)
  41.         flag = GetSaveFileName(&ofn);
  42.     else
  43.         flag = GetOpenFileName(&ofn);
  44.     ofn.lpstrTitle = old_lpstrTitle;
  45.     ofn.lpstrFile = old_lpstrFile;
  46.     ofn.nFilterIndex = FILTER_PS;
  47.     if ( save && flag && 
  48.             (psfile.name[0]!='\0') && (lstrcmp(filename, psfile.name) == 0) ) {
  49.         gserror(IDS_NOTDFNAME, NULL, MB_ICONEXCLAMATION, SOUND_ERROR);
  50.         flag = FALSE;
  51.     }
  52.     return flag;
  53. }
  54.  
  55. /* Input Dialog Box structures */
  56. LPSTR input_prop = "input_prop";
  57. struct input_param {
  58.     LPSTR prompt;
  59.     LPSTR answer;
  60. };
  61.  
  62.  
  63. /* input string dialog box */
  64. BOOL CALLBACK _export
  65. InputDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  66. {
  67.     switch(message) {
  68.         case WM_INITDIALOG:
  69.         {
  70.           HLOCAL hlocal;
  71.           LPSTR *panswer;
  72.           struct input_param *pparam = (struct input_param *)lParam;
  73.           SetDlgItemText(hDlg, ID_PROMPT, pparam->prompt);
  74.           SetDlgItemText(hDlg, ID_ANSWER, pparam->answer);
  75.           /* save address of answer string in property list */
  76.           hlocal = LocalAlloc(LHND, sizeof(pparam->answer));
  77.           panswer = (LPSTR *)LocalLock(hlocal);
  78.           if (panswer != (LPSTR *)NULL) {
  79.             *panswer = pparam->answer;
  80.         LocalUnlock(hlocal);
  81.             SetProp(hDlg, input_prop, (HANDLE)hlocal);
  82.           }
  83.         }
  84.             return( TRUE);
  85.         case WM_COMMAND:
  86.             switch(LOWORD(wParam)) {
  87.         case ID_HELP:
  88.             SendMessage(hwndimg, help_message, 0, 0L);
  89.             return(FALSE);
  90.                 case ID_ANSWER:
  91.                     return(TRUE);
  92.         case IDOK:
  93.             {
  94.               HLOCAL hlocal = (HLOCAL)GetProp(hDlg, input_prop); 
  95.               LPSTR *panswer;
  96.                   panswer = (LPSTR *)LocalLock(hlocal);
  97.                   if (panswer != (LPSTR *)NULL) {
  98.                 GetDlgItemText(hDlg, ID_ANSWER, *panswer, MAXSTR);
  99.             LocalUnlock(hlocal);
  100.               }
  101.               LocalFree(hlocal);
  102.               RemoveProp(hDlg, input_prop);
  103.             }
  104.                     EndDialog(hDlg, TRUE);
  105.                     return(TRUE);
  106.                 case IDCANCEL:
  107.             {
  108.               HLOCAL hlocal = (HLOCAL)GetProp(hDlg, input_prop); 
  109.               LocalFree(hlocal);
  110.               RemoveProp(hDlg, input_prop);
  111.             }
  112.                     EndDialog(hDlg, FALSE);
  113.                     return(TRUE);
  114.                 default:
  115.                     return(FALSE);
  116.             }
  117.         default:
  118.             return(FALSE);
  119.     }
  120. }
  121.  
  122. BOOL
  123. get_string(char *prompt, char *answer)
  124. {
  125. struct input_param param;
  126. BOOL flag;
  127. #ifndef __WIN32__
  128. DLGPROC lpProcInput;
  129. #endif
  130.     param.answer = answer;
  131.     param.prompt = prompt;
  132. #ifdef __WIN32__
  133.     flag = DialogBoxParam( phInstance, "InputDlgBox", hwndimg, InputDlgProc, (LPARAM)¶m);
  134. #else
  135.     lpProcInput = (DLGPROC)MakeProcInstance((FARPROC)InputDlgProc, phInstance);
  136.     flag = DialogBoxParam( phInstance, "InputDlgBox", hwndimg, lpProcInput, (LPARAM)¶m);
  137.     FreeProcInstance((FARPROC)lpProcInput);
  138. #endif
  139.     return flag;
  140. }
  141.  
  142.  
  143. /* copyright dialog box */
  144. BOOL CALLBACK _export
  145. AboutDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  146. {
  147.     switch(message) {
  148.         case WM_INITDIALOG:
  149.             SetDlgItemText(hDlg, ABOUT_VERSION, GSVIEW_VERSION);
  150.             return( TRUE);
  151.     case WM_LBUTTONDBLCLK:
  152.         {DWORD dwUnit = GetDialogBaseUnits();
  153.         RECT rect; POINT pt;
  154.         pt.x = LOWORD(lParam); pt.y = HIWORD(lParam);
  155.         rect.left   =   8 * LOWORD(dwUnit) / 4;
  156.         rect.top    = 138 * HIWORD(dwUnit) / 8;
  157.         rect.right  = 240 * LOWORD(dwUnit) / 4 + rect.left;
  158.         rect.bottom =   8 * HIWORD(dwUnit) / 8 + rect.top;
  159.         if (PtInRect(&rect,pt)) {
  160.         BITMAP bm;
  161.         HBITMAP hbitmap_old;
  162.         HBITMAP hbitmap = LoadBitmap(phInstance,"gsview_bitmap");
  163.         HDC hdc = GetDC(hDlg);
  164.         HDC hdcsrc = CreateCompatibleDC(hdc);
  165.         hbitmap_old = SelectObject(hdcsrc,hbitmap);
  166.         GetObject(hbitmap, sizeof(BITMAP),&bm);
  167.         BitBlt(hdc, rect.right-bm.bmWidth,rect.bottom-bm.bmHeight,
  168.            bm.bmWidth,bm.bmHeight,hdcsrc,0,0,SRCCOPY);
  169.         SelectObject(hdcsrc,hbitmap_old);
  170.         DeleteObject(hbitmap);
  171.         DeleteDC(hdcsrc);
  172.         ReleaseDC(hDlg,hdc);
  173.         }
  174.         }
  175.         return FALSE;
  176.         case WM_COMMAND:
  177.             switch(LOWORD(wParam)) {
  178.                 case IDOK:
  179.                     EndDialog(hDlg, TRUE);
  180.                     return(TRUE);
  181.                 default:
  182.                     return(FALSE);
  183.             }
  184.         default:
  185.             return(FALSE);
  186.     }
  187. }
  188.  
  189. void
  190. show_about()
  191. {
  192. #ifdef __WIN32__
  193.     DialogBoxParam( phInstance, "AboutDlgBox", hwndimg, AboutDlgProc, (LPARAM)NULL);
  194. #else
  195.     DLGPROC lpProcAbout;
  196.     lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)AboutDlgProc, phInstance);
  197.     DialogBoxParam( phInstance, "AboutDlgBox", hwndimg, lpProcAbout, (LPARAM)NULL);
  198.     FreeProcInstance((FARPROC)lpProcAbout);
  199. #endif
  200. }
  201.  
  202. /* information about document dialog box */
  203. BOOL CALLBACK _export
  204. InfoDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  205. {
  206.     switch(message) {
  207.         case WM_INITDIALOG:
  208.         info_init(hDlg);
  209.             return( TRUE);
  210.     case WM_COMMAND:
  211.             switch(LOWORD(wParam)) {
  212.                 case IDOK:
  213.                     EndDialog(hDlg, TRUE);
  214.                     return(TRUE);
  215.                 case IDCANCEL:
  216.                     EndDialog(hDlg, FALSE);
  217.                     return(TRUE);
  218.                 default:
  219.                     return(FALSE);
  220.             }
  221.         default:
  222.             return(FALSE);
  223.     }
  224. }
  225.  
  226. /* show info about ps file */
  227. void
  228. show_info()
  229. {
  230. #ifdef __WIN32__
  231.     DialogBoxParam( phInstance, "InfoDlgBox", hwndimg, InfoDlgProc, (LPARAM)NULL);
  232. #else
  233.     DLGPROC lpProcInfo;
  234.     lpProcInfo = (DLGPROC)MakeProcInstance((FARPROC)InfoDlgProc, phInstance);
  235.     DialogBoxParam( phInstance, "InfoDlgBox", hwndimg, lpProcInfo, (LPARAM)NULL);
  236.     FreeProcInstance((FARPROC)lpProcInfo);
  237. #endif
  238. }
  239.  
  240.  
  241.  
  242. #define MAX_SYSTEM_SOUND 16
  243. char *system_sounds;
  244. char *sound_entry[MAX_SYSTEM_SOUND];
  245. char szNone[32];
  246. char szSpeaker[32];
  247. int system_num;
  248. BOOL CALLBACK _export SoundDlgProc(HWND hDlg, UINT wmsg, WPARAM wParam, LPARAM lParam);
  249.  
  250. int
  251. load_sounds(void)
  252. {
  253.     char *p;
  254.     int j;
  255.  
  256.     /* add our two sounds */
  257.     sound_entry[0] = "";
  258.     sound_entry[1] = BEEP;
  259.     LoadString(phInstance, IDS_NONE, szNone, sizeof(szNone));
  260.     LoadString(phInstance, IDS_SPKR, szSpeaker, sizeof(szSpeaker));
  261.     /* get list of system sounds */
  262.     system_sounds = malloc(PROFILE_SIZE);
  263.     if (system_sounds != (char *)NULL) {
  264.         GetProfileString("sounds", NULL, "", system_sounds, PROFILE_SIZE);
  265.     }
  266.     p = system_sounds;
  267.     for (j=2; p!=(char *)NULL && j<MAX_SYSTEM_SOUND && strlen(p)!=0; j++) {
  268.         sound_entry[j] = p;    
  269.         p += strlen(p) + 1;
  270.     }
  271.     system_num = j;
  272.     return system_num;
  273. }
  274.  
  275. char *
  276. get_sound_entry(int index)
  277. {
  278.     return (sound_entry[index]);
  279. }
  280.  
  281. char *
  282. get_sound_name(int index)
  283. {
  284. static char buf[64];
  285. char *p;
  286.     if (index==0)
  287.         return szNone;
  288.     if (index==1)
  289.         return szSpeaker;
  290.         GetProfileString("sounds", sound_entry[index], ",", buf, sizeof(buf));
  291.         p = strchr(buf,',');
  292.         if (p != (char *)NULL)
  293.         return p+1;
  294.     return (char *)NULL;
  295. }
  296.  
  297. int 
  298. find_sound_name(char *entry)
  299. {
  300. int i;
  301.     for (i=0; i<system_num; i++) {
  302.         if (strcmp(entry, sound_entry[i])==0)
  303.             return i;
  304.     }
  305.     return -1;    /* no find */
  306. }
  307.  
  308. void
  309. add_sounds(HWND hDlg)
  310. {
  311. int ifile;
  312.     for (ifile=system_num-1; ifile>=0; ifile--)
  313.         SendDlgItemMessage(hDlg, SOUND_FILE, LB_INSERTSTRING, 0,
  314.              (LPARAM)(LPSTR)get_sound_name(ifile));
  315. }
  316.  
  317. void
  318. free_sounds(void)
  319. {
  320.     if (system_sounds != (char *)NULL)
  321.         free(system_sounds);
  322. }
  323.  
  324. void
  325. change_sounds(void)
  326. {
  327. #ifdef __WIN32__
  328.     LoadString(phInstance, IDS_TOPICSOUND, szHelpTopic, sizeof(szHelpTopic));
  329.     DialogBoxParam( phInstance, "SoundDlgBox", hwndimg, SoundDlgProc, (LPARAM)NULL);
  330. #else
  331.     DLGPROC lpProcSound;
  332.     LoadString(phInstance, IDS_TOPICSOUND, szHelpTopic, sizeof(szHelpTopic));
  333.     lpProcSound = (DLGPROC)MakeProcInstance((FARPROC)SoundDlgProc, phInstance);
  334.     DialogBoxParam( phInstance, "SoundDlgBox", hwndimg, lpProcSound, (LPARAM)NULL);
  335.     FreeProcInstance((FARPROC)lpProcSound);
  336. #endif
  337. }
  338.  
  339. BOOL CALLBACK _export
  340. SoundDlgProc(HWND hDlg, UINT wmsg, WPARAM wParam, LPARAM lParam)
  341. {
  342.     char buf[MAXSTR];
  343.     int ievent, ifile;
  344.     static struct sound_s dsound[NUMSOUND];    /* copy of sound[] */
  345.     WORD notify_message;
  346.     char *szWaveFilter = "*.wav";
  347.     static char szPath[MAXSTR];
  348.     static int file_start;
  349.     char *p;
  350.  
  351.     switch (wmsg) {
  352.         case WM_INITDIALOG:
  353.         file_start = load_sounds();
  354.         for (ievent=0; ievent<NUMSOUND; ievent++) {
  355.             strcpy(dsound[ievent].file, sound[ievent].file);
  356.             LoadString(phInstance, sound[ievent].title, buf, sizeof(buf));
  357.             SendDlgItemMessage(hDlg, SOUND_EVENT, LB_ADDSTRING, 0, 
  358.             (LPARAM)((LPSTR)buf));
  359.         }
  360.         ievent = 0;
  361.         SendDlgItemMessage(hDlg, SOUND_EVENT, LB_SETCURSEL, ievent, 0L);
  362.         /* force update of SOUND_FILE */
  363.         SendDlgNotification(hDlg, SOUND_EVENT, LBN_SELCHANGE);
  364.         return TRUE;
  365.         case WM_COMMAND:
  366.         notify_message = GetNotification(wParam,lParam);
  367.         switch (LOWORD(wParam)) {
  368.             case ID_HELP:
  369.                 SendMessage(hwndimg, help_message, 0, 0L);
  370.                 return(FALSE);
  371.             case SOUND_EVENT:
  372.             if (notify_message != LBN_SELCHANGE) {
  373.                 return FALSE;
  374.             }
  375.             ievent = (int)SendDlgItemMessage(hDlg, SOUND_EVENT, LB_GETCURSEL, 0, 0L);
  376.             if (ievent == LB_ERR) {
  377.                 EnableWindow(GetDlgItem(hDlg, SOUND_TEST), FALSE);
  378.                 return FALSE;
  379.             }
  380.             ifile = find_sound_name(dsound[ievent].file);
  381.             if (ifile >= 0) {
  382.                 strcpy(buf, get_sound_name(ifile));
  383.                 szPath[0] = '\0';
  384.                 EnableWindow(GetDlgItem(hDlg, SOUND_TEST), ifile!=0);
  385.             }
  386.             else {
  387.                 /* must be WAVE file */
  388.                 strcpy(szPath, dsound[ievent].file);
  389.                 p = strrchr(szPath, '\\');
  390.                 if (p != (char *)NULL) {
  391.                     strcpy(buf,++p);
  392.                     *p = '\0';
  393.                 }
  394.                 else {
  395.                     strcpy(buf, szPath);
  396.                 }
  397.                 EnableWindow(GetDlgItem(hDlg, SOUND_TEST), TRUE);
  398.             }
  399.             strcat(szPath, szWaveFilter);
  400.             DlgDirList(hDlg, szPath, SOUND_FILE, SOUND_PATH, DDL_DRIVES | DDL_DIRECTORY);
  401.             add_sounds(hDlg);
  402.             SendDlgItemMessage(hDlg, SOUND_FILE, LB_SELECTSTRING, file_start, (LPARAM)(LPSTR)buf);
  403.             return FALSE;
  404.             case SOUND_FILE:
  405.             if (notify_message == LBN_SELCHANGE) {
  406.                 ifile = (int)SendDlgItemMessage(hDlg, SOUND_FILE, LB_GETCURSEL, 0, 0L);
  407.                 SendDlgItemMessage(hDlg, SOUND_FILE, LB_GETTEXT, ifile, (LPARAM)(LPSTR)buf);
  408.                 ievent = (int)SendDlgItemMessage(hDlg, SOUND_EVENT, LB_GETCURSEL, 0, 0L);
  409.                 if (ifile >= file_start) {
  410.                 if (buf[0] == '[') { /* selected a directory */
  411.                     EnableWindow(GetDlgItem(hDlg, SOUND_TEST), FALSE);
  412.                     }
  413.                 else { /* selected a WAVE file */
  414.                             int i = GetDlgItemText(hDlg, SOUND_PATH, dsound[ievent].file, MAXSTR);
  415.                         if (dsound[ievent].file[i-1] != '\\')
  416.                             dsound[ievent].file[i++] = '\\';
  417.                             DlgDirSelectEx(hDlg, dsound[ievent].file + i, sizeof(dsound[ievent].file), SOUND_FILE);
  418.                     EnableWindow(GetDlgItem(hDlg, SOUND_TEST), TRUE);
  419.                 }
  420.                 }
  421.                 else {
  422.                 EnableWindow(GetDlgItem(hDlg, SOUND_TEST), ifile!=0);
  423.                 strcpy(dsound[ievent].file,get_sound_entry(ifile));
  424.                 }
  425.             }
  426.             if (notify_message == LBN_DBLCLK) {
  427.                 ifile = (int)SendDlgItemMessage(hDlg, SOUND_FILE, LB_GETCURSEL, 0, 0L);
  428.                 SendDlgItemMessage(hDlg, SOUND_FILE, LB_GETTEXT, ifile, (LPARAM)(LPSTR)buf);
  429.                 if (buf[0] == '[') {
  430.                         DlgDirSelectEx(hDlg, szPath, sizeof(szPath), SOUND_FILE);
  431.                     lstrcat(szPath, szWaveFilter);
  432.                         DlgDirList(hDlg, szPath, SOUND_FILE, SOUND_PATH, DDL_DRIVES | DDL_DIRECTORY);
  433.                 add_sounds(hDlg);
  434.                 }
  435.                 else {
  436.                 SendDlgNotification(hDlg, SOUND_TEST, BN_CLICKED);
  437.                 }
  438.             }
  439.             return FALSE;
  440.             case SOUND_TEST:
  441.             ievent = (int)SendDlgItemMessage(hDlg, SOUND_EVENT, LB_GETCURSEL, 0, 0L);
  442.             if (strlen(dsound[ievent].file)==0)
  443.                 return FALSE;
  444.             if (!is_win31 || (strcmp(dsound[ievent].file,BEEP)==0)) {
  445.                 MessageBeep(-1);
  446.                 return FALSE;
  447.             }
  448.             if (is_win31) {
  449.                 if (lpfnSndPlaySound != (FPSPS)NULL) 
  450.                         lpfnSndPlaySound(dsound[ievent].file, SND_SYNC);
  451.                 else
  452.                     MessageBeep(-1);
  453.                 return FALSE;
  454.             }
  455.             return FALSE;
  456.             case IDOK:
  457.             for (ievent=0; ievent<NUMSOUND; ievent++)
  458.                 strcpy(sound[ievent].file, dsound[ievent].file);
  459.             free_sounds();
  460.             EndDialog(hDlg, TRUE);
  461.             return TRUE;
  462.             case IDCANCEL:
  463.             free_sounds();
  464.             EndDialog(hDlg, FALSE);
  465.             return TRUE;
  466.         }
  467.         break;
  468.     }
  469.     return FALSE;
  470. }
  471.  
  472.  
  473. BOOL CALLBACK _export
  474. PageDlgProc(HWND hDlg, UINT wmsg, WPARAM wParam, LPARAM lParam)
  475. {
  476.     char buf[40];
  477.     int i;
  478.     WORD notify_message;
  479.     switch (wmsg) {
  480.         case WM_INITDIALOG:
  481.         if (page_list.multiple)
  482.             LoadString(phInstance, IDS_SELECTPAGES, buf, sizeof(buf));
  483.         else
  484.             LoadString(phInstance, IDS_SELECTPAGE, buf, sizeof(buf));
  485.         SetWindowText(hDlg, buf);
  486.         for (i=0; i<doc->numpages; i++) {
  487.             SendDlgItemMessage(hDlg, PAGE_LIST, LB_ADDSTRING, 0, 
  488.             (LPARAM)((LPSTR)doc->pages[map_page(i)].label));
  489.         }
  490.         SendDlgItemMessage(hDlg, PAGE_LIST, LB_SETSEL, TRUE, MAKELPARAM(page_list.current,0));
  491.         SendDlgItemMessage(hDlg, PAGE_LIST, LB_SETCURSEL, page_list.current, 0L);
  492.         if (!page_list.multiple) {
  493.             EnableWindow(GetDlgItem(hDlg, PAGE_ALL), FALSE);
  494.             EnableWindow(GetDlgItem(hDlg, PAGE_ODD), FALSE);
  495.             EnableWindow(GetDlgItem(hDlg, PAGE_EVEN), FALSE);
  496.         }
  497.         return TRUE;
  498.         case WM_COMMAND:
  499.         notify_message = GetNotification(wParam,lParam);
  500.         switch (LOWORD(wParam)) {
  501.             case PAGE_LIST:
  502.             if (notify_message == LBN_DBLCLK)
  503.                 PostMessage(hDlg, WM_COMMAND, IDOK, 0L);
  504.             return FALSE;
  505.             case PAGE_ALL:
  506.             SendDlgItemMessage(hDlg, PAGE_LIST, LB_SELITEMRANGE, TRUE, 
  507.                 MAKELPARAM(0,doc->numpages-1));
  508.             return FALSE;
  509.             case PAGE_ODD:
  510.             for (i=(int)SendDlgItemMessage(hDlg, PAGE_LIST, LB_GETCOUNT, 0, 0L)-1; i>=0; i--)
  511.                 SendDlgItemMessage(hDlg, PAGE_LIST, LB_SETSEL, !(i&1), MAKELPARAM(i,0));
  512.             return FALSE;
  513.             case PAGE_EVEN:
  514.             for (i=(int)SendDlgItemMessage(hDlg, PAGE_LIST, LB_GETCOUNT, 0, 0L); i>=0; i--)
  515.                 SendDlgItemMessage(hDlg, PAGE_LIST, LB_SETSEL, (i&1), MAKELPARAM(i,0));
  516.             SendDlgItemMessage(hDlg, PAGE_LIST, LB_SETTOPINDEX, 0, 0L);
  517.             return FALSE;
  518.             case IDOK:
  519.             i = (int)SendDlgItemMessage(hDlg, PAGE_LIST, LB_GETCURSEL, 0, 0L);
  520.             page_list.current = (i == LB_ERR) ? -1 : i;
  521.             for (i=0; i<doc->numpages; i++) {
  522.               page_list.select[i] =
  523.                 (int)SendDlgItemMessage(hDlg, PAGE_LIST, LB_GETSEL, i, 0L);
  524.             }
  525.             EndDialog(hDlg, TRUE);
  526.             return TRUE;
  527.             case IDCANCEL:
  528.             EndDialog(hDlg, FALSE);
  529.             return TRUE;
  530.         }
  531.         break;
  532.     }
  533.     return FALSE;
  534. }
  535.  
  536. /* Get page number from dialog box and store in ppage */
  537. BOOL
  538. get_page(int *ppage, BOOL multiple)
  539. {
  540. #ifndef __WIN32__
  541. DLGPROC lpProcPage;
  542. #endif
  543. BOOL flag;
  544.     if (doc == (PSDOC *)NULL)
  545.         return FALSE;
  546.     if (doc->numpages == 0) {
  547.         gserror(IDS_NOPAGE, NULL, MB_ICONEXCLAMATION, SOUND_NONUMBER);
  548.         return FALSE;
  549.     }
  550.     page_list.current = *ppage - 1;
  551.     page_list.multiple = multiple;
  552.     if (page_list.select == (BOOL *)NULL)
  553.         return FALSE;
  554.     memset(page_list.select, 0, doc->numpages * sizeof(BOOL) );
  555. #ifdef __WIN32__
  556.     flag = DialogBoxParam( phInstance, "PageDlgBox", hwndimg, PageDlgProc, (LPARAM)NULL);
  557. #else
  558.     lpProcPage = (DLGPROC)MakeProcInstance((FARPROC)PageDlgProc, phInstance);
  559.     flag = DialogBoxParam( phInstance, "PageDlgBox", hwndimg, lpProcPage, (LPARAM)NULL);
  560.     FreeProcInstance((FARPROC)lpProcPage);
  561. #endif
  562.     if (flag && (page_list.current >= 0))
  563.         *ppage = page_list.current + 1;
  564.     return flag;
  565. }
  566.  
  567. BOOL CALLBACK _export
  568. BoundingBoxDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  569. {
  570. static int bboxindex;
  571. float x, y;
  572. char buf[MAXSTR];
  573.     switch(message) {
  574.     case WM_INITDIALOG:
  575.         bboxindex = 0;
  576.         LoadString(phInstance, IDS_BBPROMPT, buf, sizeof(buf));
  577.         SetDlgItemText(hDlg, BB_PROMPT, buf);
  578.         return TRUE;
  579.     case WM_COMMAND:
  580.         switch(LOWORD(wParam)) {
  581.         case BB_CLICK:
  582.             if (!get_cursorpos(&x, &y)) {
  583.             DestroyWindow(hDlg);
  584.             hDlgModeless = 0;
  585.             }
  586.             switch(bboxindex) {
  587.             case 0:
  588.                 bbox.llx = x;
  589.                 break;
  590.             case 1:
  591.                 bbox.lly = y;
  592.                 break;
  593.             case 2:
  594.                 bbox.urx = x;
  595.                 break;
  596.             case 3:
  597.                 bbox.ury = y;
  598.                 bbox.valid = TRUE;
  599.                 break;
  600.             }
  601.             bboxindex++;
  602.             if (bboxindex <= 3) {
  603.                     LoadString(phInstance, IDS_BBPROMPT+bboxindex, buf, sizeof(buf));
  604.                     SetDlgItemText(hDlg, BB_PROMPT, buf);
  605.             return FALSE;
  606.             }
  607.         case IDCANCEL:
  608.             DestroyWindow(hDlg);
  609.             hDlgModeless = 0;
  610.             return TRUE;
  611.         }
  612.     case WM_CLOSE:
  613.         DestroyWindow(hDlg);
  614.         hDlgModeless = 0;
  615.         return TRUE;
  616.     }
  617.     return FALSE;
  618. }
  619.  
  620. BOOL
  621. get_bbox(void)
  622. {
  623. #ifndef __WIN32__
  624. DLGPROC lpfnBoundingBoxProc;
  625. #endif
  626.     bbox.valid = FALSE;
  627.     bbox.llx = bbox.lly = bbox.urx = bbox.ury = 0;
  628.     if (!display.page) {
  629.         gserror(IDS_EPSNOBBOX, NULL, MB_ICONEXCLAMATION, SOUND_ERROR);
  630.         return FALSE;
  631.     }
  632. #ifdef __WIN32__
  633.     hDlgModeless = CreateDialogParam(phInstance, "BoundingBoxDlgBox", hwndimg, BoundingBoxDlgProc, (LPARAM)NULL);
  634. #else
  635.     lpfnBoundingBoxProc = (DLGPROC)MakeProcInstance((FARPROC)BoundingBoxDlgProc, phInstance);
  636.     hDlgModeless = CreateDialogParam(phInstance, "BoundingBoxDlgBox", hwndimg, lpfnBoundingBoxProc, (LPARAM)NULL);
  637. #endif
  638.     while (hDlgModeless) {
  639.         do_message();    /* wait for bounding box to be obtained */
  640.     }
  641. #ifndef __WIN32__
  642.     FreeProcInstance((FARPROC)lpfnBoundingBoxProc);
  643. #endif
  644.     return bbox.valid;
  645. }
  646.  
  647.  
  648.